"Filed out from Dolphin Smalltalk 7"!

STUnitTest subclass: #RoundedRateCombiningCalculatorTest
	instanceVariableNames: 'data calculator'
	classVariableNames: ''
	poolDictionaries: ''
	classInstanceVariableNames: ''!
RoundedRateCombiningCalculatorTest guid: (GUID fromString: '{D3F2715B-3DDE-4D44-82A4-D68ADA63FC13}')!
RoundedRateCombiningCalculatorTest comment: ''!
!RoundedRateCombiningCalculatorTest categoriesForClass!Unclassified! !
!RoundedRateCombiningCalculatorTest methodsFor!

setUp
	super setUp.
	data := RosemarkDataFactory new.
	data
		allowAdditionalSelectors: #(#assignment);
		default: #isMedicaid with: true;
		default: #serviceTypeCode with: [data isMedicaid ifTrue: [#MEDICAID] ifFalse: [#HM]];
		default: #serviceType
			withAdditional: 
				[:st | 
				(st addBillRateEffective: '10/01/2006' asDate) baseRate: 5.50s.
				data isMedicaid ifTrue: 
						[st 
							testingBeMedicaidAsOf: '10/01/2006'
							unitDuration: 30
							baseRate: 5.50s]];
		default: #shiftStatus with: ShiftStatus verifiedComplete;
		default: #shifts with: [self setUpShifts];
		default: #zeroedShifts with: [self setUpZeroedShifts].!

setUpShifts
	^#('11/01/06 10a-11:23a' '11/01/06 12n-2:14p' '11/02/06 10a-10:44a' '11/02/06 12n-1:56p' '11/03/06 10a-11:12a' '11/04/06 10a-11:48a' '11/04/06 12n-3:35p' '11/04/06 4p-4:34p' '11/05/06 10a-11:25a') 
		collect: [:each | data createShiftAt: each].!

setUpZeroedShifts
	^#('11/01/06 9a-9:10a' '11/01/06 10a-10:10a' '11/01/06 11a-11:10a' '11/01/06 12n-12:10p' '11/01/06 1p-1:10p' '11/01/06 2p-2:10p' '11/01/06 3p-3:10p' '11/01/06 4p-4:10p') 
		collect: [:each | data createShiftAt: each].!

testFlatRate
	data isMedicaid: false.
	(data serviceType explicitBillRateAsOf: '10/01/2006' asDate) rateType: RateType flat.
	ReportCombiningType instancesDo: 
			[:rcType | 
			calculator := RoundedRateCombiningCalculator 
						newForShifts: data shifts
						roundingPer: rcType
						combiningPer: ReportCombiningType day.
			self assert: calculator finalUnits asArray = #(2 2 1 3 1)].!

testMaxRate
	data isMedicaid: false.
	(data serviceType explicitBillRateAsOf: '10/01/2006' asDate)
		rateType: RateType max;
		rateTypeParameter: 2.00s.
	ReportCombiningType instancesDo: 
			[:rcType | 
			calculator := RoundedRateCombiningCalculator 
						newForShifts: data shifts
						roundingPer: rcType
						combiningPer: ReportCombiningType shift.
			self 
				assert: calculator finalUnits asArray = #(1.38s 2.00s 0.73s 1.93s 1.20s 1.80s 2.00s 0.57s 1.42s)].!

testNonQuantizedRateCombineByDay
	data isMedicaid: false.
	(data serviceType explicitBillRateAsOf: '10/01/2006' asDate)
		rateType: RateType ratio;
		rateTypeParameter: 8.
	ReportCombiningType instancesDo: 
			[:rcType | 
			calculator := RoundedRateCombiningCalculator 
						newForShifts: data shifts
						roundingPer: rcType
						combiningPer: ReportCombiningType day.
			self assert: calculator finalUnits asArray = #(1.20s 0.88s 0.40s 1.98s 0.47s)].!

testNonQuantizedRateCombineByPeriod
	data isMedicaid: false.
	(data serviceType explicitBillRateAsOf: '10/01/2006' asDate)
		rateType: RateType ratio;
		rateTypeParameter: 8.
	ReportCombiningType instancesDo: 
			[:rcType | 
			calculator := RoundedRateCombiningCalculator 
						newForShifts: data shifts
						roundingPer: rcType
						combiningPer: ReportCombiningType period.
			self assert: calculator finalUnits asArray = #(4.93s)].!

testNoShifts
	calculator := RoundedRateCombiningCalculator 
				newForShifts: #()
				roundingPer: ReportCombiningType shift
				combiningPer: ReportCombiningType shift.
	self assert: calculator finalResults isEmpty.!

testRatioRate
	data isMedicaid: false.
	(data serviceType explicitBillRateAsOf: '10/01/2006' asDate)
		rateType: RateType ratio;
		rateTypeParameter: 8.
	ReportCombiningType instancesDo: 
			[:rcType | 
			calculator := RoundedRateCombiningCalculator 
						newForShifts: data shifts
						roundingPer: rcType
						combiningPer: ReportCombiningType shift.
			self 
				assert: calculator finalUnits asArray = #(0.46s 0.74s 0.24s 0.64s 0.40s 0.60s 1.19s 0.19s 0.47s)].!

testRoundByDayCombineByDay
	calculator := RoundedRateCombiningCalculator 
				newForShifts: data shifts
				roundingPer: ReportCombiningType day
				combiningPer: ReportCombiningType day.
	self assert: calculator finalUnits asArray = #(8 6 3 12 3).
	data serviceType datedBillRates first roundingMode: RoundingMode down.
	self assert: calculator finalUnits asArray = #(7 5 2 11 2).
	data serviceType datedBillRates first roundingMode: RoundingMode nearest.
	self assert: calculator finalUnits asArray = #(7 5 2 12 3).!

testRoundByDayCombineByPeriod
	calculator := RoundedRateCombiningCalculator 
				newForShifts: data shifts
				roundingPer: ReportCombiningType day
				combiningPer: ReportCombiningType period.
	self assert: calculator finalUnits asArray = #(32).
	data serviceType datedBillRates first roundingMode: RoundingMode down.
	self assert: calculator finalUnits asArray = #(27).
	data serviceType datedBillRates first roundingMode: RoundingMode nearest.
	self assert: calculator finalUnits asArray = #(29).!

testRoundByDayCombineByShift
	calculator := RoundedRateCombiningCalculator 
				newForShifts: data shifts
				roundingPer: ReportCombiningType day
				combiningPer: ReportCombiningType shift.
	self assert: calculator finalUnits asArray = #(3 5 2 4 3 4 6 2 3).
	data serviceType datedBillRates first roundingMode: RoundingMode down.
	self assert: calculator finalUnits asArray = #(3 4 2 3 2 3 7 1 2).
	data serviceType datedBillRates first roundingMode: RoundingMode nearest.
	self assert: calculator finalUnits asArray = #(3 4 1 4 2 4 7 1 3).!

testRoundByPeriodCombineByDay
	calculator := RoundedRateCombiningCalculator 
				newForShifts: data shifts
				roundingPer: ReportCombiningType period
				combiningPer: ReportCombiningType day.
	self assert: calculator finalUnits asArray = #(8 6 3 10 3).
	data serviceType datedBillRates first roundingMode: RoundingMode down.
	self assert: calculator finalUnits asArray = #(7 5 3 11 3).
	data serviceType datedBillRates first roundingMode: RoundingMode nearest.
	self assert: calculator finalUnits asArray = #(7 5 3 12 3).!

testRoundByPeriodCombineByPeriod
	calculator := RoundedRateCombiningCalculator 
				newForShifts: data shifts
				roundingPer: ReportCombiningType period
				combiningPer: ReportCombiningType period.
	self assert: calculator finalUnits asArray = #(30).
	data serviceType datedBillRates first roundingMode: RoundingMode down.
	self assert: calculator finalUnits asArray = #(29).
	data serviceType datedBillRates first roundingMode: RoundingMode nearest.
	self assert: calculator finalUnits asArray = #(30).!

testRoundByPeriodCombineByShift
	calculator := RoundedRateCombiningCalculator 
				newForShifts: data shifts
				roundingPer: ReportCombiningType period
				combiningPer: ReportCombiningType shift.
	self assert: calculator finalUnits asArray = #(3 4 2 4 3 4 5 2 3).
	data serviceType datedBillRates first roundingMode: RoundingMode down.
	self assert: calculator finalUnits asArray = #(3 4 3 3 2 3 7 2 2).
	data serviceType datedBillRates first roundingMode: RoundingMode nearest.
	self assert: calculator finalUnits asArray = #(3 4 2 4 2 4 7 1 3).!

testRoundByShiftCombineByDay
	calculator := RoundedRateCombiningCalculator 
				newForShifts: data shifts
				roundingPer: ReportCombiningType shift
				combiningPer: ReportCombiningType day.
	self assert: calculator finalUnits asArray = #(8 6 3 14 3).
	data serviceType datedBillRates first roundingMode: RoundingMode down.
	self assert: calculator finalUnits asArray = #(6 4 2 11 2).
	data serviceType datedBillRates first roundingMode: RoundingMode nearest.
	self assert: calculator finalUnits asArray = #(7 5 2 12 3).!

testRoundByShiftCombineByPeriod
	calculator := RoundedRateCombiningCalculator 
				newForShifts: data shifts
				roundingPer: ReportCombiningType shift
				combiningPer: ReportCombiningType period.
	self assert: calculator finalUnits asArray = #(34).
	data serviceType datedBillRates first roundingMode: RoundingMode down.
	self assert: calculator finalUnits asArray = #(25).
	data serviceType datedBillRates first roundingMode: RoundingMode nearest.
	self assert: calculator finalUnits asArray = #(29).!

testRoundByShiftCombineByShift
	calculator := RoundedRateCombiningCalculator 
				newForShifts: data shifts
				roundingPer: ReportCombiningType shift
				combiningPer: ReportCombiningType shift.
	self assert: calculator finalUnits asArray = #(3 5 2 4 3 4 8 2 3).
	data serviceType datedBillRates first roundingMode: RoundingMode down.
	self assert: calculator finalUnits asArray = #(2 4 1 3 2 3 7 1 2).
	data serviceType datedBillRates first roundingMode: RoundingMode nearest.
	self assert: calculator finalUnits asArray = #(3 4 1 4 2 4 7 1 3).!

testShiftPartitioningOrderIsRetained
	self 
		assert: ((ReportCombiningType shift partitionShifts: data shifts) flattened 
				collect: [:each | each duration asHoursString]) asArray 
				= #('1.38' '2.23' '0.73' '1.93' '1.20' '1.80' '3.58' '0.57' '1.42').
	self 
		assert: ((ReportCombiningType day partitionShifts: data shifts) flattened 
				collect: [:each | each duration asHoursString]) asArray 
				= #('1.38' '2.23' '0.73' '1.93' '1.20' '1.80' '3.58' '0.57' '1.42').
	self 
		assert: ((ReportCombiningType period partitionShifts: data shifts) flattened 
				collect: [:each | each duration asHoursString]) asArray 
				= #('1.38' '2.23' '0.73' '1.93' '1.20' '1.80' '3.58' '0.57' '1.42').!

testSimpleRate
	"Wanted to have the bare amounts to gut-check the results in #testRatioRate"

	data isMedicaid: false.
	ReportCombiningType instancesDo: 
			[:rcType | 
			calculator := RoundedRateCombiningCalculator 
						newForShifts: data shifts
						roundingPer: rcType
						combiningPer: ReportCombiningType shift.
			self assert: calculator finalAmounts asArray 
						= #(7.59s 12.27s 4.02s 10.62s 6.60s 9.90s 19.69s 3.14s 7.81s)].!

testZeroedShifts
	data serviceType datedBillRates first rateTypeParameter: 15.
	calculator := RoundedRateCombiningCalculator 
				newForShifts: data zeroedShifts
				roundingPer: ReportCombiningType period
				combiningPer: ReportCombiningType shift.
	self assert: calculator finalUnits asArray = #(1 1 1 1 1 1).
	data serviceType datedBillRates first roundingMode: RoundingMode down.
	self assert: calculator finalUnits asArray = #(1 1 1 1 1).
	data serviceType datedBillRates first roundingMode: RoundingMode nearest.
	self assert: calculator finalUnits asArray = #(1 1 1 1 1).! !
!RoundedRateCombiningCalculatorTest categoriesFor: #setUp!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #setUpShifts!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #setUpZeroedShifts!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testFlatRate!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testMaxRate!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testNonQuantizedRateCombineByDay!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testNonQuantizedRateCombineByPeriod!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testNoShifts!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testRatioRate!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testRoundByDayCombineByDay!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testRoundByDayCombineByPeriod!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testRoundByDayCombineByShift!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testRoundByPeriodCombineByDay!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testRoundByPeriodCombineByPeriod!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testRoundByPeriodCombineByShift!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testRoundByShiftCombineByDay!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testRoundByShiftCombineByPeriod!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testRoundByShiftCombineByShift!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testShiftPartitioningOrderIsRetained!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testSimpleRate!public! !
!RoundedRateCombiningCalculatorTest categoriesFor: #testZeroedShifts!public! !

